package online.sh.cn.fy.common.servlet;

import java.io.IOException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import online.sh.cn.fy.common.utils.CookieUtil;


/**
 * 	35%为https://fx.sh.189.cn/mininet/fusion/qrCodeToIndex
 *
 *	65%为以下地址中任意随机，几率相同
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=396
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=402
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=412
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=411
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=413
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=414
 *
 *	https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=415
 */
@WebServlet("/produceurl")
public class produceUrl extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String openid=CookieUtil.getCookieValueByName(request, "openid");
		if(null!=openid && ""!=openid){
			SecureRandom sr=new SecureRandom();
			int flag=sr.nextInt(10);
			if(flag<4){
//				response.sendRedirect("https://fx.sh.189.cn/mininet/fusion/qrCodeToIndex");
//				response.sendRedirect("https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html");
				response.sendRedirect("https://fx.sh.189.cn/mininet/fusion/qrCodeToIndex?schoolNumber=-1");
			}else{
				String a="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=396";
//				String b="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=402";
//				String c="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=412";
//				String d="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=411";
//				String e="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=413";
//				String f="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=414";
//				String g="https://fx.sh.189.cn/mininet/fusion/dailyFillOrder.html?schoolNumber=415";
//				List list = Arrays.asList(new String[]{a,b,c,d,e,f,g});
//				response.sendRedirect(list.get(sr.nextInt(7)).toString());
				response.sendRedirect(a);
			}
		}else{
			response.sendRedirect("index.html");
		}
	}
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
}
